﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using System.Net;
using com.lover.common;
using System.IO;
using com.lover.astd.common.model;
using com.lover.common.http;

namespace com.lover.astd.common.partner.impl
{
    public class Kuwan8Login : LoginImplBase
    {
        private string _randNum = "88234";
        private string _checkCode = "3607";
        public Kuwan8Login() : base() { }
        public override LoginResult login(ref List<Cookie> cookies, string verify_code = null, string extra = null)
        {
            LoginResult result = new LoginResult();
            logging();
            //"a=login&RandNum=88234&username="+escape(sUserName)+"&code="+hex_md5(sUserPass)+hex_md5(sCheckCode)
            //  +"&cache="+Math.random()+"&checked="+checked;
            string loginurl = String.Format(
                "http://www.kuwan8.com/user/userloginajax.aspx?a=login&RandNum={0}&username={1}&code={2}{3}&cache={4}&checked=0;",
                _randNum, _username, _md5_password_lower, CommonUtils.generateStringMd5(_checkCode), _rand.NextDouble());
            HttpResult resp = TransferMgr.doGetPure(loginurl, ref cookies);
            if (resp == null) { result.StatusCode = LoginStatusCode.FailInLogin; return result; }

            string retstr = resp.getContent();
            // ERR$$$用户名或者密码错误   SUC$$$....
            if (retstr.IndexOf("ERR$$$") >= 0)
            {
                result.StatusCode = LoginStatusCode.FailInLogin;
                return result;
            }

            string redirecturl = String.Format("http://www.kuwan8.com/user/gotogame.aspx?gid=4&zid={0}", _acc.ServerId);

            processRedirect(redirecturl, result, ref cookies);
            return result;
        }
    }
}
